fix #4278: proxy all methods in ProxiedProducer/Consumer#4358
fix #4278: proxy all methods in ProxiedProducer/Consumer#4358JMGalvao wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
|
Thanks for this! Please pull as I did a changelog resolve before triggering workflows. Please then could you address the lint issues with:
|
Remove Producer/Consumer inheritance from ProxiedProducer and ProxiedConsumer. Add __getattr__ to delegate undefined methods to the wrapped client, fixing segfaults on calls like list_topics() or assignment(). Add regression tests to verify delegation of undefined methods on both proxy classes.
2baa7b6 to
a4419bd
Compare
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Thanks again! Maintainers will also have a look
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
| return super().close() | ||
|
|
||
|
|
||
| class ProxiedProducer(Producer): |
There was a problem hiding this comment.
Isn't this going to break any isinstance() that may be used by downstream users? I think the right solution would be to use wrapt object proxies instead.
There was a problem hiding this comment.
Yeah, I missed this before. This is right, it would be a breaking change and any isinstance calls would now return False.
I agree using wrapt would be a better solution.
MikeGoldsmith
left a comment
There was a problem hiding this comment.
As per @xrmx's comment, this would be a breaking change. We should consider using wrapt instead to keep the type hierarchy the same.
Description
Fixes #4278
ProxiedProducerandProxiedConsumerinherited from the confluent-kafka C-extension classes (Producer/Consumer) but never calledsuper().__init__(). Any method not explicitly defined on the proxy class fell through to the base class with an uninitialized C handle, causingRuntimeError: Handle has been closed/Consumer closed.The fix removes inheritance and uses pure composition with
__getattr__to delegate all undefined method calls to the wrapped instance.Type of Change
Testing
Added two regression tests:
test_proxied_producer_delegates_undefined_methods— callslist_topics()onProxiedProducerand verifies it delegates to the underlying producertest_proxied_consumer_delegates_undefined_methods— callsassignment()onProxiedConsumerand verifies it delegates to the underlying consumerDoes This Require a Core Repo Change?
Checklist